package de.reichelt.fxrequi.data;

import de.reichelt.fx.FxOption;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class Project {
  private final StringProperty name = new SimpleStringProperty();
  private final StringProperty title = new SimpleStringProperty();
  private final ObjectProperty<FxOption> state = new SimpleObjectProperty<>();
  private final StringProperty descr = new SimpleStringProperty();
  private final ObjectProperty<Date> dateCreated = new SimpleObjectProperty<>();
  private final StringProperty userCreated = new SimpleStringProperty();
  private final StringProperty keywords = new SimpleStringProperty();
  
  public static List<FxOption> states = Arrays.asList(new FxOption("new", "neu"), 
          new FxOption("active", "in Bearbeitung"), 
          new FxOption("suspended", "abgebrochen"));
      
  

  public Project() {
  }
  
  public Project(String name, String title, FxOption state, String descr, 
          Date dateCreated, String userCreated, String keywords) {
    setName(name);
    setTitle(title);
    setState(state);
    setDescr(descr);
    setDateCreated(dateCreated);
    setUserCreated(userCreated);
    setKeywords(keywords);
  }
  
  public String getKeywords() {
    return keywords.get();
  }

  public void setKeywords(String value) {
    keywords.set(value);
  }

  public StringProperty keywordsProperty() {
    return keywords;
  }
  
  public String getUserCreated() {
    return userCreated.get();
  }

  public void setUserCreated(String value) {
    userCreated.set(value);
  }

  public StringProperty userCreatedProperty() {
    return userCreated;
  }
  
  public Date getDateCreated() {
    return dateCreated.get();
  }

  public void setDateCreated(Date value) {
    dateCreated.set(value);
  }

  public ObjectProperty dateCreatedProperty() {
    return dateCreated;
  }
  
  public String getName() {
    return name.get();
  }

  public void setName(String value) {
    name.set(value);
  }

  public StringProperty nameProperty() {
    return name;
  }
  
  public String getTitle() {
    return title.get();
  }

  public void setTitle(String value) {
    title.set(value);
  }

  public StringProperty titleProperty() {
    return title;
  }
  
  public FxOption getState() {
    return state.get();
  }

  public void setState(FxOption value) {
    state.set(value);
  }

  public ObjectProperty<FxOption> stateProperty() {
    return state;
  }
  
  public String getDescr() {
    return descr.get();
  }

  public void setDescr(String value) {
    descr.set(value);
  }

  public StringProperty descProperty() {
    return descr;
  }

  @Override
  public String toString() {
    return title.get();
  }
  
  public static FxOption getState(String key) {
    for (FxOption opt: states) {
      if (opt.getKey().equals(key)) {
        return opt;
      }
    }
    return null;
  }
  
  public static FxOption getStateByValue(String value) {
    for (FxOption opt: states) {
      if (opt.getValue().equals(value)) {
        return opt;
      }
    }
    return null;
  }

}
